package b1.scenes.fight
{
	import b1.conifg.Config;
	import b1.conifg.ObjectConfig;
	import b1.controls.basic.BasicMc;
	import b1.net.ResourceHelper;
	import b1.utils.BFont;
	
	import com.greensock.TimelineLite;
	import com.greensock.TweenLite;
	
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class ArmDropMc extends Sprite
	{
		private var backgroundImgRatio:Number;
		private var clueMcBackground:BasicMc;
		private const clueMcBackgroundConst:int = 60;
		private var clueMcImg:Sprite;
		private var text:TextField;
		//type，0，从右下向左上
		public function ArmDropMc(armIndex:int, type:int = 0)
		{
			super();
			//添加背景
			var ClueMcBackground:Class = ResourceHelper.getInstance().getClassByName("ClueMcBackground");
			clueMcBackground = new BasicMc(ClueMcBackground, 10);
			backgroundImgRatio = clueMcBackgroundConst  /  clueMcBackground.height;
			clueMcBackground.height = backgroundImgRatio * clueMcBackground.height;
			clueMcBackground.width = backgroundImgRatio * clueMcBackground.width;
			clueMcBackground.x = - clueMcBackground.width / 2;
			clueMcBackground.y =  - clueMcBackground.height / 2;
			addChild(clueMcBackground);
			
			var objectConfig:ObjectConfig = Config.objectConfigs[armIndex];

			//添加装备图片
			var ClueMcImg:Class = ResourceHelper.getInstance().getClassByName(objectConfig.iconImage);
			clueMcImg = new ClueMcImg();
			var ratio:Number = clueMcBackgroundConst / (clueMcImg.height * 2);
			clueMcImg.height = ratio * clueMcImg.height;
			clueMcImg.width = ratio * clueMcImg.width;
			clueMcImg.x = - clueMcImg.width / 2;
			clueMcImg.y =  - clueMcImg.height / 2;
			addChild(clueMcImg);
			//添加文字
			text = new TextField();
			var txtFormat:TextFormat;
			if (objectConfig.name.length < 6)
        	{
        		txtFormat = new TextFormat("微软雅黑", 9, 0xFFFF00);
        	}
        	else
        	{
        		txtFormat = new TextFormat("微软雅黑", 7, 0xFFFF00);
        	}
			txtFormat.align = TextFieldAutoSize.CENTER;
			text.defaultTextFormat = txtFormat;
			text.text = objectConfig.name.substr(0,6);
			text.width = text.text.length * 18;
			text.x =  - text.width / 2;
			text.y = clueMcImg.y + clueMcImg.height;
			addChild(text);
		}
		
		public function move():void
		{
			var myTimeLine:TimelineLite = new TimelineLite();
			//中间位置的坐标
			var aimX1:Number = (BFont.stageWidth - clueMcBackground.width) / 2 - this.parent.x;
			var aimY1:Number = (BFont.stageWidth - clueMcBackground.height) / 2 - this.parent.y - 150;
			//终点位置的坐标
			var aimX2:Number = 50 - this.parent.x;
			var aimY2:Number = 600 - this.parent.y - 420;
			myTimeLine.append(new TweenLite(this, 0.5, {x: aimX1, y: aimY1, scaleX:1 / backgroundImgRatio, scaleY:1 / backgroundImgRatio, rotation:720}));
			myTimeLine.append(new TweenLite(this, 1, {x: aimX1, y: aimY1, scaleX:1 / backgroundImgRatio, scaleY:1 / backgroundImgRatio}));
			myTimeLine.append(new TweenLite(this, 0.5, {x: aimX2, y:aimY2, scaleX:backgroundImgRatio / 4, scaleY:backgroundImgRatio / 4, rotation:720, onComplete: onComplete}));
		}
		
		private function onComplete():void
		{
			if (null != text)
			{
				removeChild(text);
			}
			if (null != this)
			{
				this.parent.removeChild(this);
			}
		}
		
	}
}